package com.yeheng.test.homework2;

/**
 * @PackgeName: com.yeheng.test.homework2
 * @ClassName: MyThread2
 * @Author: YH
 * Date: 2021/1/1 19:27
 * project name: homework1
 * @Version:
 * @Description:
 */
public class MyThread2 implements Runnable{
    private int i = 1;
    @Override
    public void run() {
        while (true){
            synchronized (MyThread2.class){
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                String name = Thread.currentThread().getName();
                if ("线程1".equals(name)||"线程3".equals(name)){
                    i++;
                    System.out.println(name+"正在进行操作i为：   "+i);
                }else {
                    i--;
                    System.out.println(name+"正在进行操作i为：   "+i);
                }
            }
        }
    }
}
